<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    	<title>统战成员学习平台</title>
	    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
	    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
	</head>
	<body class="white">
		<div id="app" style="display:none" v-show="true">
			<div v-if="hasHeader" class="cata_header">目录<i @click="closeSide()" class="icon_close_big"></i></div>
			<ul class="lesson_catalog">
				<li v-for="(item, index) of items" :class="{'active': activeIndex === index}">
					<i :class="activeIndex === index ? 'icon_s_close' : 'icon_s_open'"></i>
					<div class="ui_border_b" @click="collapse(index)">{{item.nodeName}}</div>
					<ul>
						<li tapmode @click="study(i)" v-for="i of item.sub" class="ui_border_b"><span class="point"></span>{{i.nodeName}}</li>
					</ul>
				</li>
			</ul>
		</div>
		<script type="text/javascript" src="../../script/api.js"></script>
		<script type="text/javascript" src="../../script/vue.min.js"></script>
		<script type="text/javascript" src="../../script/common.js"></script>
		<script type="text/javascript" src="../../script/layer_mobile/layer.js"></script>
		<script type="text/javascript">
		    new Vue({
				el: '#app',
		     	data: {
					courseId: 0,
					hasHeader: false,
					activeIndex: -1,
					items: []
		     	},
				mounted: function() {
		        	var $this = this;
		        	apiready = function() {
						$this.courseId = api.pageParam.courseId;
						$this.hasHeader = api.pageParam.hasHeader;
                        if($this.hasHeader) document.body.classList.remove('white');
						setTimeout(function() {
							var header = $api.dom('.cata_header');
							if(header) {
								$api.fixStatusBar(header);
							}
						}, 0)
						$this.init();
                	}
		    	},
		    	methods: {
					init: function() {
						var $this = this;
						post('/client/coursefront/view', {courseId: $this.courseId}, function(ret) {
							ret.data.forEach(function(item) {
								if(item.type === 0) {
									item.sub = [];
									$this.items.push(item)
								} else {
									$this.items.forEach(function(zhang) {
										if(zhang.catalogId === item.catalogPId) {
											zhang.sub.push(item)
										}
									})
								}
							});
						})
					},
					collapse: function(i) {
						this.activeIndex = this.activeIndex === i ? -1 : i
					},
					closeSide: function() {
						api.closeDrawerPane()
					},
					study: function(item) {
						api.sendEvent({
						    name: 'study_new_chapter_event',
						    extra: {
						        catalogId: item.catalogId
						    }
						});
						api.closeDrawerPane()
					}
		    	}
		    });
		</script>
	</body>
</html>
